(function(angular) {
    "use strict";

    var filter_module = angular.module("cloapCertificateApp.filter");

    filter_module.filter("certificate_names", function certificateNames() {
        return function certificateNamesFilter(lost_papers) {
            return _.pluck(lost_papers, "name").join(",");
        };
    });

    filter_module.filter("toggleState", function toggleState() {
        return function toggleStateFilter(state, prefix) {
            prefix = prefix || "toggle_";
            if(state === "enable") {
                return prefix + "disable";
            }
            return prefix + "enable";
        };
    });

    filter_module.filter("ldapUserId", function getLdapUserId() {
        return function getLdapUserIdFilter(ldap_dn) {
            var LDAP_UID_REG = /uid=(\w*),/;

            return LDAP_UID_REG.exec(ldap_dn)[1];
        };
    });

    filter_module.filter("hasDuedateCertificate", function hasDuedateCertificate() {
        return function hasDuedateCertificateFilter(employees) {
            return _.filter(employees, function filterUser(employee) {
                return employee.duedate_papers.length > 0;
            });
        };
    });

    filter_module.filter("percentage", function() {
      return function(value, precision) {
          precision = precision || 2;
          return parseFloat(value).toFixed(precision) + "%";
      }; 
    });

}(angular));
